package com.mrx.pvzcommunity.service;

import com.mrx.pvzcommunity.dao.SiteInfoDao;
import com.mrx.pvzcommunity.model.Response;
import com.mrx.pvzcommunity.model.Result;
import com.mrx.pvzcommunity.model.SiteInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SiteInfoService {
    private final SiteInfoDao siteInfoDao;
    private final SiteInfo siteInfo = new SiteInfo();

    public Result<SiteInfo> getSiteInfo() {
        this.siteInfo.setPlantNum(siteInfoDao.countPlants());
        this.siteInfo.setZombieNum(siteInfoDao.countZombies());
        this.siteInfo.setUserNum(siteInfoDao.countUsers());
        this.siteInfo.setThreadNum(siteInfoDao.countUserThreads());
        this.siteInfo.setCommentNum(siteInfoDao.countComments());

        return Result.createResult(Response.Code.SUCCESS, siteInfo);
    }
}
